from classpath.entry import Entry


class CompositeEntry(Entry):
    def __init__(self, entries):
        self.entries = entries

    def readClass(self, className):
        for entry in self.entries:
            content, _ = entry.readClass(className)
            if content is not None:
                return content, self
        return None, self

    def __str__(self):
        return ", ".join([str(item) for item in self.entries])

    @staticmethod
    def newCompositeEntry(path: str):
        entries = []
        for path in path.split(Entry.SEPARATOR):
            entries.append(Entry.newEntry(path))
        return CompositeEntry(entries)


